package wqh.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import wqh.domain.Monitor;

import java.util.List;

/**
 * Created by devts on 2016/9/26.
 */
public interface MonitorDao {

    List<Monitor> findAllRecord();

    @Insert("INSERT INTO monitor (geo_level_1_id, geo_level_2_id, geo_level_3_id,device_id,sensor_id, name, pos_x, pos_y, description) " +
            "VALUES(#{geo_level_1_id},#{geo_level_2_id},#{geo_level_3_id},#{device_id}, #{sensor_id}, #{name}, #{pos_x}, #{pos_y}, #{description})")
    int insertRecord(Monitor monitor);

    @Update("UPDATE monitor SET geo_level_1_id = #{geo_level_1_id}, geo_level_2_id = #{geo_level_2_id}, geo_level_3_id = #{geo_level_3_id}," +
            "device_id = #{device_id}, sensor_id = #{sensor_id}, name = #{name}, pos_x = #{pos_x}, pos_y = #{pos_y}, description = #{description} WHERE id = #{id}")
    int updateRecord(Monitor monitor);

    @Delete("DELETE FROM monitor WHERE id = #{1}")
    int deleteRecord(Integer id);

    @Update("UPDATE monitor SET description = #{0} WHERE id = #{1}")
    int updateDescriptionById(String description, Integer id);

    @Update("UPDATE monitor SET name = #{0} WHERE id = #{1}")
    int updateNameById(String name, Integer id);

    @Update("UPDATE monitor SET pos_x = #{0}, pos_y = #{1} WHERE id = #{2}")
    int updatePosById(String pos_x, String pos_y, Integer id);

    @Select("SELECT * FROM monitor WHERE id = #{1}")
    Monitor findAllById(Integer id);

    @Select("SELECT * FROM monitor WHERE geo_level_3_id = #{1}")
    List<Monitor> findAllByGeoLevel3(Integer id);

    @Select("SELECT * FROM monitor WHERE description = #{1}")
    List<Monitor> findAllByCode(String description);

    @Select("SELECT * FROM monitor WHERE device_id = #{0} AND description = #{1}")
    List<Monitor> findAllByDeviceAndCode(Integer device_id, String code);


}
